//
//  TestRelationShip.m
//  CoreDataDemo
//
//  Created by chenguibang on 16/2/29.
//  Copyright © 2016年 chenguibang. All rights reserved.
//

#import "TestRelationShip.h"
#import "DptDAO.h"
#import "DptModel.h"
#import "SalaryDAO.h"
#import "PostDAO.h"

@interface TestRelationShip ()

@end

@implementation TestRelationShip

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSArray *titleArr = [NSArray arrayWithObjects:@"add",@"del",@"update",@"query",@"back", nil];
    for (int i = 0; i< titleArr.count; i++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 35*(i+2), 150, 33)];
        [btn setTitle:titleArr[i] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor orangeColor];
        [btn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchDown];
        [self.view addSubview:btn];
    }
}

-(void)btn:(UIButton*)ss{
    if ([ss.titleLabel.text isEqualToString:@"add"]) {
        DptDAO *dao = [[DptDAO alloc]init];
        DptModel *model = [[DptModel alloc]init];
        model.dp_deptname = @"HR";
        [dao insert:model];
        
        
        model.dp_deptname = @"DEV";
        [dao insert:model];
        
        model.dp_deptname = @"POD";
        [dao insert:model];
        
        
        
        SalaryDAO *sdao = [[SalaryDAO alloc]init];
        SalaryModel *smodel = [[SalaryModel alloc]init];
        smodel.sy_level = @"A";
        smodel.sy_scale = [NSNumber numberWithDouble:5632.0];
        
        [sdao insert:smodel];
        
        
        smodel.sy_level = @"B";
        smodel.sy_scale = [NSNumber numberWithDouble:4000.0];
        
        [sdao insert:smodel];
        
        smodel.sy_level = @"C";
        smodel.sy_scale = [NSNumber numberWithDouble:3000.0];
        
        [sdao insert:smodel];
        
        smodel.sy_level = @"D";
        smodel.sy_scale = [NSNumber numberWithDouble:2000.0];
        
        [sdao insert:smodel];
        
        
        PostDAO *pdap = [[PostDAO alloc]init];
        PostModel *pmodel = [[PostModel alloc]init];
        pmodel.pt_name = @"清洁";
        pmodel.dept = model;
        pmodel.salary = smodel;
        [pdap insert:pmodel];
        
        

        pmodel.pt_name = @"开发";
        pmodel.dept = model;
        pmodel.salary = smodel;
        [pdap insert:pmodel];
        
        
        pmodel.pt_name = @"大家";
        pmodel.dept = model;
        pmodel.salary = smodel;
        [pdap insert:pmodel];
        
        
        
    }else if ([ss.titleLabel.text isEqualToString:@"del"]){
        
        
    }else if ([ss.titleLabel.text isEqualToString:@"update"]){
        
        
        
    }else if ([ss.titleLabel.text isEqualToString:@"query"]){
        
    }else if ([ss.titleLabel.text isEqualToString:@"back"]){
        TestRelationShip *t = [[TestRelationShip alloc]init];
        [self dismissViewControllerAnimated:NO completion:^{
            
        }];
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
